﻿using System;
using System.Threading;
using System.Threading.Tasks;
using Caliburn.Micro;
using JY.Wpf.Core.Events;
using JY.Wpf.Core.ViewModelBases;

namespace JY.Wpf.TestForMetro.ViewModels.ControlDemoViewModels
{
    /// <summary>
    /// 等待遮罩层ViewModel
    /// </summary>
    public class BusyIndicatorDemoViewModel:ViewModelBase
    {
        #region 执行中
        public async void ExecuteBusyIndicator()
        {
            this.EventAggregator.PublishOnUIThread(new BusyIndicatorEvent(true, $"加载中{DateTime.Now}..."));
            await Task.Run(() => Thread.Sleep(1000));
            this.EventAggregator.PublishOnUIThread(new BusyIndicatorEvent(false));
        } 
        #endregion

        #region # 获取页面 —— object GetView(object context = null)
        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return ResolveMediator.Resolve<BusyIndicatorDemoView>();
        }
        #endregion
    }
}
